package FIT::Document::Handler::Execute;

use FIT::Class;

extends 'FIT::Document::Handler::Base';

sub handle {
    my ($fixture, $element, @handlers) = @_;
    my $method = 'handle_'. $element->tag;
    $self->$method($fixture, $element, @handlers);
}

sub handle_tr {
    my ($fixture, $row, @handlers) = @_;

    # before row processing
    $fixture->reset($row);
    $self->has_executed($fixture, 0);

    $self->run_next_handler($fixture, $row, @handlers);

    # after row processing
    $fixture->execute($row) unless $self->has_executed($fixture);
}

sub handle_td {
    my ($fixture, $cell, @handlers) = @_;

    # execute before 1st output cell
    if ($cell->fit_is_output_cell && !$self->has_executed($fixture)) {
        $self->has_executed($fixture, 1);
        $fixture->execute($cell->row);
    }

    $self->run_next_handler($fixture, $cell, @handlers);
}

sub has_executed { $self->fixture_state(has_executed => @_) }


=head1 NAME

FIT::Document::Handler::Execute - xxx


=head1 DESCRIPTION

XXX

=cut

